obj = {
	add:function () {
		var awin = $('#addWin');
		awin.panel({title: "新增模式"}).dialog("open");
	},
	addSon:function () {
		var node = $('#chargeConfig_data').treegrid('getSelected');
		if(node!=null){
			if(node.fatherId==null){
				var awin = $('#addSonWin');
				$("#fatherId").val(node.id);
				awin.panel({title: "新增配置"}).dialog("open");
			}else{
				$.messager.alert("提示信息","请选中一个模式!");
			}
		}else{
			$.messager.alert("提示信息","请选择一条记录!");
		}
	},
	edit:function(){
		  var node = $('#chargeConfig_data').treegrid('getSelected');
		  if(node!=null){
			  if(node.fatherId==null){
				  if(node.isEffective=="Y"){
					  $.messager.alert("提示信息","正在使用的设置不能修改!");
				  }else{
					  var ewin = $('#editWin');
					  $.post(basePath+"/chargeConfig/load.json",{'id':node.id},function(res){
						  ewin.form('load', {
							  chargeType : res.data.chargeType,
							  region : res.data.region,
							  sequence:res.data.sequence,
							  id:res.data.id
						  }).dialog('open');
					  });
				  }
			  }else{
				  var node1=$('#chargeConfig_data').treegrid('find',node.fatherId);
				  if(node1.isEffective=="Y"){
					   $.messager.alert("提示信息","正在使用的设置不能修改!");
				  }else{
					  var eSonwin = $('#editSonWin');
					  $.post(basePath+"/chargeConfig/load.json",{'id':node.id},function(res){
						  eSonwin.form('load', {
							  chargeName : res.data.chargeName,
							  unitValue : res.data.unitValue,
							  start : res.data.start,
							  end : res.data.end,
							  sequence:res.data.sequence,
							  fatherId : res.data.fatherId,
							  id:res.data.id
						  }).dialog('open');
					  });
				  }
			  }
		  }else{
			  $.messager.alert("提示信息","请选择一条记录!");
		  }
	},
	deletes:function(){
		var node = $('#chargeConfig_data').treegrid('getSelected');
		if(node!=null){
//			$.ajax({
//				url: basePath+"/chargeConfig/delete.json",
//				type:'post',
//				data:{"id":node.id},
//				success:function(result,response,status){
//					if(result.success){
//						$.messager.alert("提示信息",result.msg);
//						$('#chargeConfig_data').treegrid('reload');
//					}else{
//						$.messager.alert("提示信息",result.msg);
//					}
//				}
//			});
			
			$.post(basePath+"/chargeConfig/delete.json",{"id":node.id},function(data){
				if(data.success){
					$('#chargeConfig_data').treegrid('reload');
				}else{
					$.messager.alert({showSpeed:100,title:'消息提示',msg:data.msg,timeout:3000});
				}
			});
		}else{
			$.messager.alert("提示信息","请选择一条记录!");
		}
	},
	effective:function(){
		var node = $('#chargeConfig_data').treegrid('getSelected');
		if(node!=null){
			if(node.fatherId==null){
//				$.ajax({
//					url: basePath+"/chargeConfig/setEffective.json",
//					type:'post',
//					data:{"id":node.id},
//					success:function(result,response,status){
//						if(result.success){
//							$('#chargeConfig_data').treegrid('reload');
//						}else{
//							$.messager.alert("提示信息",result.msg);
//						}
//					}
//				});
				
				$.post(basePath+"/chargeConfig/setEffective.json",{"id":node.id},function(data){
					if(data.success){
						$('#chargeConfig_data').treegrid('reload');
					}else{
						$.messager.alert({showSpeed:100,title:'消息提示',msg:data.msg,timeout:3000});
					}
				});
			}else{
				$.messager.alert("提示信息","请选中一个模式!");
			}
		}else{
			$.messager.alert("提示信息","请选择一条记录!");
		}
	},
	noEffective:function(){
		var node = $('#chargeConfig_data').treegrid('getSelected');
		if(node!=null){
			if(node.fatherId==null){
//				$.ajax({
//					url: basePath+"/chargeConfig/setNoEffective.json",
//					type:'post',
//					data:{"id":node.id},
//					success:function(result,response,status){
//						if(result.success){
//							$.messager.alert("提示信息",result.msg);
//							$('#chargeConfig_data').treegrid('reload');
//						}else{
//							$.messager.alert("提示信息",result.msg);
//						}
//					}
//				});
				
				$.post(basePath+"/chargeConfig/setNoEffective.json",{"id":node.id},function(data){
					if(data.success){
						$.messager.alert("提示信息",data.msg);
						$('#chargeConfig_data').treegrid('reload');
					}else{
						$.messager.alert({showSpeed:100,title:'消息提示',msg:data.msg,timeout:3000});
					}
				});
			}else{
				$.messager.alert("提示信息","请选中一个模式!");
			}
		}else{
			$.messager.alert("提示信息","请选择一条记录!");
		}
	}
	
};

	
$(function(){
	$('#chargeConfig_data').treegrid({
		url: basePath+"/chargeConfig/findByTreePage.json",
	    method: 'get',
	    striped : true,
		nowrap : true,
		rownumbers : true,
		fitColumns : true,
		singleSelect:true,
		border:false,
		idField: 'id',
	    treeField: 'chargeType',
		toolbar:'#tb_sb',
		scrollbarSize:1,
//		title:'设备',
		columns:[[
	          {field:'chargeType',align:'center','title':'电费模式',width:200},
	          {field:'chargeName',align:'center','title':'电费名称',width:200},
	          {field:'unitValue',align:'center','title':'单位电费',width:100},
	          {field:'startTime',align:'center','title':'开始时间',width:150,formatter: function(value){if(value){return moment(value).format("HH:mm");}else{return null;}}},
	          {field:'endTime',align:'center','title':'结束时间',width:150,formatter: function(value){if(value){return moment(value).format("HH:mm");}else{return null;}}},
	          {field:'sequence',align:'center','title':'顺序',width:200},
	          {field:'region',align:'center','title':'地区',width:200},
	          {field:'isEffective',align:'center','title':'是否有效',width:100}
        ]],
	    pagination : true,
  		pageList : [5,10],
  		pageNumber : 1,
		pageSize : 10,
  		pagePosition : 'bottom'
	});
	
	$('#dts').timespinner({    
//	    min: getStartDate(),    
	    required: true,    
	    showSeconds: false   
	});
	$('#dte').timespinner({    
//	    min: '00:00',    
	    required: true,    
	    showSeconds: false   
	});
	//新增配置
	$('#addSonWin').dialog({
		width:400,
		height:300,
		iconCls:'icon-add',
		closed: true,
		modal: true,
		inline:true,
		buttons:[{
			text:'提交',
			iconCls:'icon-add-new',
			handler:function(){
				if($('#addSonform').form('validate')){
					$.post(basePath+"/chargeConfig/save.json",$("#addSonform").serialize(),function(data){
						if(data.success){
							$('#addSonWin').dialog('close');
							$('#chargeConfig_data').treegrid('reload');
						}else{
							$.messager.alert({showSpeed:100,title:'消息提示',msg:data.msg,timeout:3000});
						}
					});
				}
			}
		},{
			text:'取消',
			iconCls:'icon-redo',
			handler:function(){
				$('#addSonWin').dialog('close');
			}
		}],
		onClose: function() {
			$('#addSonform').form('reset');
		}
	});
	$('#dts_e').timespinner({    
	    required: true,    
	    showSeconds: false   
	});
	$('#dte_e').timespinner({    
	    required: true,    
	    showSeconds: false   
	});
	//编辑配置
	$('#editSonWin').dialog({
		title:"编辑配置",
		width:400,
		height:300,
		iconCls:'icon-edit',
		closed: true,
		modal: true,
		inline:true,
		buttons:[{
			text:'提交',
			iconCls:'icon-add-new',
			handler:function(){
				if($('#editSonform').form('validate')){
					$.ajax({
						url: basePath+"/chargeConfig/update.json",
						type:'post',
						data:$('#editSonform').serialize(),
						success:function(result,response,status){
							if(result!=null){
								$.messager.alert("提示信息",result.msg);
								$('#editSonWin').dialog('close');
								$('#chargeConfig_data').treegrid('reload');
							}else{
								$.messager.alert("提示信息","操作失败");
							}
						}
					});
					
					$.post(basePath+"/chargeConfig/update.json",$("#editSonform").serialize(),function(result){
						if(result.success){
							$('#editSonWin').dialog('close');
							$('#chargeConfig_data').treegrid('reload');
						}else{
							$.messager.alert({showSpeed:100,title:'消息提示',msg:restlt.msg,timeout:3000});
						}
					});
				}
			}
		},{
			text:'取消',
			iconCls:'icon-redo',
			handler:function(){
				$('#editSonWin').dialog('close');
			}
		}],
		onClose: function() {
			$('#editSonform').form('reset');
		}
	});
	//新增模式
	$('#addWin').dialog({
		width:400,
		height:150,
		iconCls:'icon-add',
		closed: true,
		modal: true,
		inline:true,
		buttons:[{
			text:'提交',
			iconCls:'icon-add-new',
			handler:function(){
				if($('#addform').form('validate')){
					$.post(basePath+"/chargeConfig/save.json",$("#addform").serialize(),function(data){
						if(data.success){
							$('#addWin').dialog('close');
							$('#chargeConfig_data').treegrid('reload');
						}else{
							$.messager.alert({showSpeed:100,title:'消息提示',msg:data.msg,timeout:3000});
						}
					});
				}
			}
		},{
			text:'取消',
			iconCls:'icon-redo',
			handler:function(){
				$('#addWin').dialog('close');
			}
		}],
		onClose: function() {
			$('#addform').form('reset');
		}
	});
	//编辑模式
	$('#editWin').dialog({
		title:"编辑模式",
		width:400,
		height:150,
		iconCls:'icon-edit',
		closed: true,
		modal: true,
		inline:true,
		buttons:[{
			text:'提交',
			iconCls:'icon-add-new',
			handler:function(){
				if($('#editform').form('validate')){
//					$.ajax({
//						url: basePath+"/chargeConfig/update.json",
//						type:'post',
//						data:$('#editform').serialize(),
//						success:function(result,response,status){
//							if(result!=null){
//								$.messager.alert("提示信息",result.msg);
//								$('#editWin').dialog('close');
//								$('#chargeConfig_data').treegrid('reload');
//							}else{
//								$.messager.alert("提示信息","操作失败");
//							}
//						}
//					});
					
					$.post(basePath+"/chargeConfig/update.json",$("#editform").serialize(),function(result){
						if(result.success){
							$('#editWin').dialog('close');
							$('#chargeConfig_data').treegrid('reload');
						}else{
							$.messager.alert({showSpeed:100,title:'消息提示',msg:restlt.msg,timeout:3000});
						}
					});
				}
			}
		},{
			text:'取消',
			iconCls:'icon-redo',
			handler:function(){
				$('#editWin').dialog('close');
			}
		}],
		onClose: function() {
			$('#editform').form('reset');
		}
	});
});
